Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Adding try_state hook(tips & vesting) #13515

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

Doordashcon
Copy link
Contributor

@Doordashcon Doordashcon commented Mar 2, 2023

part of paritytech/polkadot-sdk#239
polkadot address: 12zsKEDVcHpKEWb99iFt3xrTCQQXZMu477nJQsTBBrof5k2h

frame/society/src/mock.rs Outdated Show resolved Hide resolved
@kianenigma kianenigma added the A0-please_review Pull request needs code review. label Mar 16, 2023
frame/tips/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the right track, but needs a bit more work.

@kianenigma
Copy link
Contributor

Would be good if you update the PR title to say which pallets it includes.

@Doordashcon Doordashcon changed the title Adding try_state hook Adding try_state hook(vesting, tips & sudo) Mar 17, 2023
@Doordashcon Doordashcon changed the title Adding try_state hook(vesting, tips & sudo) Adding try_state hook(vesting & tips) Mar 18, 2023
@Doordashcon Doordashcon changed the title Adding try_state hook(vesting & tips) Adding try_state hook(tips & vesting) Mar 20, 2023
@Doordashcon Doordashcon marked this pull request as ready for review March 20, 2023 17:15
@Doordashcon
Copy link
Contributor Author

I have ran the try-state expectations of Tips and Vesting pallet against the current Polkadot state, please review :)

@Doordashcon
Copy link
Contributor Author

Tips

Vesting

Comment on lines 156 to 159
ext.execute_with(|| {
System::set_block_number(1);
Vesting::do_try_state().unwrap();
});
Copy link
Contributor

@liamaharon liamaharon Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this doesn't really test much because it runs before there's any state set up to test?

I suggest that you

  1. test that the try-state hooks will detect the issues that they're supposed to, check out how that's done here: https://github.com/paritytech/substrate/blob/master/frame/bags-list/src/list/tests.rs#L353-L378 (also do this with tips)
  2. pepper assert_ok!(vesting::do_try_state());s into existing tests, like you did with tips

Copy link
Contributor Author

@Doordashcon Doordashcon May 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But i still think it's all the same and there's no need to pepper existing tests, the current setup in vesting tests the genesis state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if I'm missing something, but I think we should test all functionality not just the genesis state?

Like bags-list there should be tests ensuring that the try-state hooks actually detect the issues that they're supposed to: https://github.com/paritytech/substrate/blob/master/frame/bags-list/src/list/tests.rs#L353-L378

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @liamaharon , I have made updates to this. Please review

Copy link
Contributor

@liamaharon liamaharon May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests ensuring that the try-state hooks detects the issues they are intended to. They’d have picked up a bug in the assert (see other comment)

frame/vesting/src/lib.rs Outdated Show resolved Hide resolved
let mut total_per_block: BalanceOf<T> = Zero::zero();
let mut total_locked_now: BalanceOf<T> = Zero::zero();
for info in vesting.iter() {
// get the number of remaining vesting blocks<>balance
Copy link
Contributor

@liamaharon liamaharon Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the number of blocks remaining are converted to balance

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this comment with this clarification

frame/vesting/src/lib.rs Outdated Show resolved Hide resolved
frame/vesting/src/lib.rs Outdated Show resolved Hide resolved
frame/vesting/src/lib.rs Outdated Show resolved Hide resolved
@liamaharon liamaharon added B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels Apr 21, 2023
@Doordashcon Doordashcon requested a review from a team May 15, 2023 15:27
Copy link
Contributor

@liamaharon liamaharon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mean to sound harsh, but this PR was not ready to be re-reviewed.

The core logic of the vesting try-state hook is broken, there’s an ignored suggestion from the last review which would have uncovered that issue, and comments had not been updated to reflect code changes.

Please only request review after you have addressed comments from the previous review and thoroughly checked your logic, code and comments.

I suggest that you step back from the code for a minute, think about the invariant/s you are testing, and thoughtfully plan the logic that that will test these invariants, writing it down in a plain English doc comment. Then as you codify that logic, write tests to ensure that the code is working as you intended, detecting failure cases as well as letting through success cases.

Comment on lines 687 to 688
let one_extra = total_to_vest.saturating_sub(total_locked);
assert_eq!(total_to_vest, total_locked.saturating_add(one_extra));
Copy link
Contributor

@liamaharon liamaharon May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what this is checking is:

if one_extra = total_to_vest - total_locked does total_to_vest = one_extra + total_locked?

or more abstractly

if x = y - z, then does y = x + z?

of course it will always be true, you're asserting that 1 == 1.

let mut total_per_block: BalanceOf<T> = Zero::zero();
let mut total_locked_now: BalanceOf<T> = Zero::zero();
for info in vesting.iter() {
// get the number of remaining vesting blocks<>balance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this comment with this clarification

let amount_left: BalanceOf<T> =
info.ending_block_as_balance::<T::BlockNumberToBalance>();
total_to_vest += info.per_block().saturating_mul(amount_left);
// get the total block<>balance still locked.
Copy link
Contributor

@liamaharon liamaharon May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please replace this block<>balance shorthand throughout the comments with just plain English

Comment on lines 664 to 665
/// * The `per_block` amount left to be claimed is equal to the
/// total balance currently locked.
Copy link
Contributor

@liamaharon liamaharon May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated variable name in comment

Comment on lines 667 to 671
/// *`total_to_vest` the total amount left to vest over all remaining blocks.
/// *`total_locked` the total amount locked.
///
/// * `one_extra` accounts for the extra block that
/// will be added to the vesting schedule if `per_block` is bigger than `locked`.
Copy link
Contributor

@liamaharon liamaharon May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add documentation for variables the line above where the variable is declared, rather than in the doc comment

Comment on lines 156 to 159
ext.execute_with(|| {
System::set_block_number(1);
Vesting::do_try_state().unwrap();
});
Copy link
Contributor

@liamaharon liamaharon May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests ensuring that the try-state hooks detects the issues they are intended to. They’d have picked up a bug in the assert (see other comment)

@paritytech-ci paritytech-ci requested a review from a team May 16, 2023 20:08
@juangirini juangirini added the T1-runtime This PR/Issue is related to the topic “runtime”. label Jun 12, 2023
@Doordashcon Doordashcon requested a review from a team June 28, 2023 07:33
@Doordashcon
Copy link
Contributor Author

Hello @liamaharon, if you could spare some time...

I am currently trying to denote where the logic is that updates the VestingInfo as block number increases(i.e bob has a vesting info of { locked: 256, per_block: 12, starting_block: 10}).

Time(moment) passes and now we are at block 11, locked gets updated to reflect this.

This is the logic I am searching for, the one that knows to execute the update.

@Doordashcon Doordashcon requested a review from ggwpez August 8, 2023 12:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

6 participants